package com.example.babybus.util

import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import androidx.core.app.ActivityCompat

object PermissionUtil {
    const val location_code = 100

    // 定位权限
    private val location = arrayOf<String>(
        android.Manifest.permission.ACCESS_COARSE_LOCATION,
        android.Manifest.permission.ACCESS_FINE_LOCATION
    )

    fun checkLocation(context: Context): Boolean {
        location.forEach {
            if (ActivityCompat.checkSelfPermission(
                    context,
                    it
                ) != PackageManager.PERMISSION_DENIED
            ) {
                return false
            }
        }
        return true
    }

    fun requestLocation(activity: Activity) {
        ActivityCompat.requestPermissions(activity, location, location_code)
    }
}